package com.demo.project_template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.demo.project_template.entity.UserWallet;
import com.demo.project_template.service.UserWalletService;
import com.demo.project_template.vo.request.order.ExchangeVO;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户钱包 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:58
 */
@Api(tags = "用户钱包")
@RestController
@RequestMapping("/userWallet")
public class UserWalletController {
    @Resource
    private UserWalletService userWalletService;

    @ApiOperation(value = "获取用户钱包")
    @GetMapping(value = "/get")
    public R<UserWallet> get(@RequestParam Long userId){
        UserWallet userWallet = userWalletService.getOne(new LambdaQueryWrapper<UserWallet>().eq(UserWallet::getUserId, userId));
        return R.success(userWallet);
    }

    @ApiOperation(value = "积分兑换金币")
    @PostMapping(value = "/integralExchange")
    public R<?> integralExchange(@RequestBody ExchangeVO exchangeVO){
        userWalletService.integralExchange(exchangeVO);
        return R.success();
    }
}
